home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / VOL_400 / 466_01 / SRC / FMTCONST.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-20  |  2.6 KB  |  149 lines

  1. #include <afx.h>
  2. #include <afxtempl.h>
  3. #include "parse.h"
  4. #include "input.h"
  5. #include "fmt.h"
  6. #include "fmtconst.h"
  7. #include "errmsg.h"
  8.  
  9.  
  10. /******************************************************/
  11. // Tag list
  12. /******************************************************/
  13.  
  14. TAGSPEC gtagsConstSection[] =
  15. {
  16.     CFmtListConst::tagDefine,           "define",
  17.     CFmtListConst::tagOutput,           "output",
  18.     -1,        NULL,
  19. };
  20.  
  21.  
  22. /******************************************************/
  23. // Format class
  24. /******************************************************/
  25.  
  26. CFmtConst::CFmtConst(void) : CFmtBase(1)
  27. {
  28. }
  29.  
  30.  
  31.  
  32. CFmtConst::CFmtConst(const char *szName, const char *szText) : CFmtBase(1)
  33. {
  34.     m_sName = szName;
  35.     
  36.     m_aFmtStrings[0] = new CString(szText);
  37. }
  38.  
  39.  
  40.  
  41. int CFmtConst::Match(CFmtSrchBase *psrch)
  42. {
  43.     CFmtSrchConst *psrchConst = (CFmtSrchConst *)psrch;
  44.  
  45.     ASSERT(psrchConst);
  46.  
  47.     // See if tag names match
  48.  
  49.     return _strcmpi(psrchConst->m_sName, m_sName) == 0;
  50. }
  51.  
  52. #ifdef _DEBUG
  53. void CFmtConst::Dump(CDumpContext &dc) const
  54. {
  55.     CFmtBase::Dump(dc);
  56.  
  57.     dc << "\tName: "<< m_sName;
  58. }
  59. #endif
  60.  
  61.  
  62.  
  63.  
  64.  
  65. /******************************************************/
  66. // List class
  67. /******************************************************/
  68.  
  69. TAGSPEC *CFmtListConst::FmtTagList(void)
  70. {
  71.     return gtagsConstSection;
  72. }
  73.     
  74.  
  75. int CFmtListConst::ParseEntry(CFmtInput &in)
  76. {
  77.     CFmtConst *pNew;
  78.     const char *sz;
  79.     const char *szEnd;
  80.     static char szNameTerm[] = "\t ";
  81.     int nRet;
  82.     
  83.     switch(m_nTag)
  84.     {
  85.     // Parent
  86.  
  87.     case tagOutput:
  88.         
  89.         // Expect: .output = output
  90.  
  91.         if(in.m_nTokens != 1)
  92.             return fmterrBadEntryCount;
  93.  
  94.         CheckOutputType(in, 0);
  95.  
  96.         break;
  97.  
  98.     case tagDefine:
  99.         // expect: .define=name , format string
  100.  
  101.         if(m_nState.Skip)
  102.             return 0;
  103.  
  104.         if(in.m_nTokens < 2)
  105.             return fmterrBadEntryCount;
  106.  
  107.         // Make a new one
  108.  
  109.         nRet = CheckAddTag();
  110.         if(nRet)
  111.             return nRet;
  112.  
  113.         m_pNew = pNew = new CFmtConst;
  114.  
  115.         m_nState.Tag = TRUE;
  116.  
  117.         // Get the constant name.
  118.  
  119.         if((sz = SeekLetter(in.m_aszTokens[0])) == NULL)
  120.             return fmterrExpectedName;
  121.     
  122.         szEnd = SeekEnd(sz, szNameTerm, MAXTAGSIZE);
  123.         if(szEnd == NULL)
  124.             return fmterrBadTagName;
  125.  
  126.         pNew->m_sName = CString(sz, szEnd-sz);
  127.  
  128.         sz = szEnd;
  129.  
  130.         // Record source file information.
  131.  
  132.         pNew->SetSource(in.m_nFile, in.m_lCurLine);
  133.         
  134.         // Set the format string.
  135.  
  136.         nRet = SetFmtString(in, 1);
  137.  
  138.         if(nRet)
  139.             return nRet;
  140.         break;
  141.  
  142.     default:
  143.         return fmterrBadFmtEntry;
  144.     }
  145.  
  146.     return 0;
  147. }
  148.  
  149.